package com.myebills.ebpsfrontend.cust.maxis;

import com.myebills.ebpsfrontend.cust.controller.*;
import com.myebills.ebpsfrontend.cust.utils.*;
import com.checkfree.isolutions.customer.persist.Account;
import com.checkfree.isolutions.customer.persist.User;
import com.checkfree.isolutions.admin.ObjectId;
import com.checkfree.isolutions.statement.persist.Statement;
import java.util.Vector;
import java.util.*;
import java.text.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.myebills.maxis.paypal.SOAPaymentCheckoutServiceStub.*;
import org.apache.axiom.om.*;
import org.apache.axiom.om.impl.llom.OMElementImpl;
import java.io.*;
import com.myebills.maxis.paypal.*;

public class PaypalCheckoutServlet extends EbppxTransactionServlet {

    public void doTransaction(
    HttpServletRequest req,
    HttpServletResponse res)
    throws ServletException {
        try {
            final HttpSession session = req.getSession(false);

            if (null == session)
                throw new IllegalStateException("no session established");

            final EbppxUrlManager urlManager = getUrlManager(req);

            final String accountId   = urlManager.getSecureParameter("accid");
            final String paymentAmt   = urlManager.getSecureParameter("amt");
            final String statid   = urlManager.getSecureParameter("statid");

            System.out.println("PaypayCheckout: Account Id "+accountId);
            System.out.println("PaypayCheckout: Payment amount "+paymentAmt);

            float fPaymentAmt = Float.valueOf(paymentAmt.trim()).floatValue();

            SOAPaymentInitiateClient soaPaymentInitiateClient = new SOAPaymentInitiateClient();
            String returnURL = soaPaymentInitiateClient.initiatePaymentCheckout(accountId, fPaymentAmt);
            //String returnURL = "http://www.google.com";

			System.out.println("PaypalCheckoutServlet, redirect to " + returnURL);

            //forwardToMappedUrl(req, res, returnURL);
            res.sendRedirect(res.encodeRedirectURL(returnURL));
        }
        catch (Throwable t) {
            throw new ServletException(t.toString(), t);
        }
    }
}